<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width"/>
    <meta name="viewport" content="initial-scale=1.0,user-scalable=no"/>
    <meta name="apple-mobile-web-app-capable" content="yes">

    <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.js"></script>
    <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
    <script type="text/javascript">
        function intOnly() {
            var codeNum = $.trim($("#mypositioningPhoneNumber").val());
            if (codeNum == "") {
                alert("手机号不能为空");
                return false;
            }
            if (codeNum.length != 11) {
                alert("手机号只能为11位数字");
            }
            if (codeNum == 8 || codeNum == 37 || codeNum == 39 || (codeNum >= 48 && codeNum <= 57)) {
                event.returnValue = codeNum;
            } else {
                event.returnValue = false;
            }
        }

        function toViewMap() {
            var mypositioningPhoneNumber = $.trim($("#mypositioningPhoneNumber").val());
            var mypositioningName = $.trim($("#mypositioningName").val());
            console.log('mypositioningPhoneNumber:' + mypositioningPhoneNumber + 'mypositioningName:' + mypositioningName);

            if (mypositioningPhoneNumber == "") {
                alert("手机号码不能为空");
                return false;
            }

            if (mypositioningPhoneNumber.length != 11) {
                alert("手机号码长度必须为11位");
                return false;
            }
            $.ajax({
                type: "POST",
                url: "/mypositioning/viewMap",
                data: {"mypositioningPhoneNumber": mypositioningPhoneNumber, "mypositioningName": mypositioningName},
                cache: false,
                dataType: "json",
                complete: function (ret) {
                    var jsonVar = JSON.parse(ret.responseText);
                    if (jsonVar.status == 1 && jsonVar.code == "0000") {
                        // alert(jsonVar.object);
                        window.location.href = jsonVar.object;
                    } else if ("session超时,请重新登录" == jsonVar.message) {
                        alert(jsonVar.message);
                        window.location.href = "/userManagement/loginIndex";
                    } else {
                        $("#mypositioningPhoneNumber").val("");
                        $("#mypositioningName").val("")
                        alert(jsonVar.message);
                    }
                },error:function(retMsg){
                    alert("session超时,请重新登录");
                    window.location.href = "/userManagement/loginIndex";
                }
            });
        }
    </script>

</head>
<body>
<form method="post">
    <input type="text" id="mypositioningPhoneNumber"
           name="mypositioningPhoneNumber"
           placeholder="请输入对方手机号" maxlength="11"
           onchange="intOnly();"/>
    <input type="text" id="mypositioningName" name="mypositioningName" placeholder="请输入联系人姓名(选填)"/>
    <input type="button" value="获取定位" onclick="toViewMap();"/>
</form>
</body>
</html>